﻿<!-- Web Upload Account search PHP File -->
<!-- Reveions History ...
	Rev 1.00 at 2015/06/08 by Max Yin:
		1. First time create
	Rev 1.01 at 2015/07/08 by Max Yin:
		1. 由標楷體, 改成新細明體
-->
<html>
	<body background="pic/background_06.gif">
	<head>
		<font face="新細明體,time new roman,Arial">
		<meta charset="UTF-8">
	</head>
	<body>
		<center>
			<font size="5" color="#0000FF"><b>--- 查询结果 ---</b></font><br> 
			<hr>
			<?php
				require_once('class_package/common.php');
				$partnum 	  = $_POST['partnum'];
				$begin1 	  = $_POST['begin'];
				$finish1 	  = $_POST['end'];
				$a		 	  = '00:00:00';
				$b		 	  = '23:59:59';
				$begin 	 	  = $begin1.' '.$a;
				$finish  	  = $finish1.' '.$b;				
				$str 		  = strtolower($partnum);
				$begin_date   = strtotime(date($begin));
				$finish_date  = strtotime(date($finish));
				$show_num	  = 0;
				$db_select    = Sql_Download::sql_db;
				$db_table     = Sql_Download::sql_table;
				$table_name1  = Sql_Download::table_name1;
				$conn         = '';
				$sql_cmd      = '';
				$rows         = 0;
				$result       = '';
				$starStr = 'PROJECT PE : ';
				$endStr = ' N/A';
				$regex = '/NOT Exists/i';
				$client = new SoapClient('http://sf_ws.joytech.com.cn/ShopfloorWebService/Service_AP.asmx?wsdl');
				$client->soap_defencoding = 'utf-8';  
				$client->decode_utf8 = false;   
				$client->xml_encoding = 'utf-8';
				if (strlen($begin1) > 0 && strlen($finish1) == 0) {
					echo "<script>alert('請輸入結束時間點');history.go(-1);</script>";
					exit();
				}
				
				if (strlen($begin1) == 0 && strlen($finish1) > 0) {
					echo "<script>alert('請輸入開始時間點');history.go(-1);</script>";
					exit();
				}
				
				if ($begin_date > $finish_date) {
					echo "<script>alert('请确认所填写的时间顺序');history.go(-1);</script>";
					exit();
				}
				
				if ( $str == 'all' ) {
					setcookie('seach_user',$str);
					$conn = mysqli_connect(html::sql_login_host,html::sql_login_user,html::sql_login_pass,$db_select);
					if ( mysqli_connect_errno($conn) ) { 
						echo "<script>alert('MySql资料库连接失败,请联系开发人员,并查明原因...');history.go(-1);</script>";
						exit();
					}
					mysqli_set_charset($conn,'set names utf8');					

					$sql_cmd = "SELECT * FROM `$db_table` ORDER BY `$table_name1` ASC";
					$result = mysqli_query($conn,$sql_cmd);	// 透过 execute_query 对象实例完成查询
					if ( !$result ) { 
						mysqli_close($conn);				// 关闭资料库
						echo "<script>alert('MySql资料库搜寻失败,请跟开发人员查明原因...');history.go(-1);</script>";
						exit();
					}
					
					$rows = mysqli_num_rows($result);		// 返回结果集中栏位的数量。
					if ( $rows == 0 ) { 
						mysqli_close($conn);				// 关闭资料库
						echo "<script>alert('MySql资料库获取栏位数失败...');history.go(-1);</script>";
						exit();
					}
					
					echo '<br>
					<table border="2" width="75%">
						<tr bgcolor="#70DB93">
							<th>No.</th>
							<th>工單</th>
							<th>Model Name</th>
							<th>Part Number</th>
							<th>WSID</th>
							<th>TPVER</th>
							<th>Create Date/Time</th>
							<th>Create By</th>
							<th>下載數</th>
							<th>近期下載</th>
						</tr>';
					
					while ( $getArray = mysqli_fetch_array($result,MYSQLI_ASSOC) ) {
						$show_num++;
						$put_pn          = $getArray['webdl_pn'];
						$put_wsid        = $getArray['webdl_wsid'];
						$put_tpver       = $getArray['webdl_tpver'];
						$put_work_order  = $getArray['webdl_work_order'];
						$put_line        = $getArray['webdl_line'];
						$put_panel       = $getArray['webdl_panel'];
						$put_create_date = $getArray['webdl_create_date'];
						$put_creator     = $getArray['webdl_creator'];
						$put_description = $getArray['webdl_description'];
						$put_ftpip       = $getArray['webdl_ftpip'];
						$put_count       = $getArray['webdl_count'];
						$put_date        = $getArray['webdl_download_date'];
						
						$param=array('INPUTSTRING'=>"<INPUTSTRING><rowset><DataType>A_NOTES_UPDATE_PRJECT_PE</DataType><KEY_PART_NO>$put_pn</KEY_PART_NO><Return_Formate>XML</Return_Formate></rowset></INPUTSTRING>");
						$res = $client->__Call("getSFData", array( $param ));
						if (is_soap_fault($res)) {
							trigger_error("SOAP Fault: (faultcode: {$res->faultcode}, faultstring: {$res->faultstring})", E_USER_ERROR);
						} else {
							$data = $res->getSFDataResult; //这里返回的是类，必须使用->得到元素的值	
							
							if ( preg_match($regex,$data)){
								$model ="NOT Exists";
							} else {
								$start  = strpos($data,$starStr)+strlen($starStr);	//检索PROJECT PE : 在字符串中首次出现的位置。
								$end 	= strpos($data,$endStr);						//检索 N/A在字符串中末尾出现的位置。
								$model  = substr($data,$start,$end-$start);
							}													
						}
												
						echo "
							<tr>
								<th>$show_num</th>
								<th><font size='4' color='#0000FF'><b>$put_work_order</b></font></th>
								<th>$model</th>
								<th>$put_pn</th>
								<th>$put_wsid</th>
								<th>$put_tpver</th>
								<th>$put_create_date</th>
								<th>$put_creator</th>
								<th>$put_count</th>
								<th>$put_date</th>
							</tr>";
					}
					echo '</table><br>';
					mysqli_free_result($result);			// 释放 MySQL $result
					mysqli_close($conn);					// 关闭资料库
				} elseif ( strlen($begin1) > 0 && strlen($finish1) > 0 && strlen($partnum) == 0 ) {
						
					$c	  = 0;
					$conn = mysqli_connect(html::sql_login_host,html::sql_login_user,html::sql_login_pass,$db_select);
					if ( mysqli_connect_errno($conn) ) { 
						echo "<script>alert('MySql资料库连接失败,请联系开发人员,并查明原因...');history.go(-1);</script>";
						exit();
					}
					mysqli_set_charset($conn,'set names utf8');
					
					$sql_cmd = "SELECT * FROM `$db_table` ORDER BY `$table_name1` ASC";
					
					$result = mysqli_query($conn,$sql_cmd);	// 透过 execute_query 对象实例完成查询
					if ( !$result ) { 
						mysqli_close($conn);				// 关闭资料库
						echo "<script>alert('MySql资料库搜寻失败,请跟开发人员查明原因...');history.go(-1);</script>";
						exit();
					}
					
					$rows = mysqli_num_rows($result);		// 返回结果集中栏位的数量。
					if ( $rows == 0 ) { 	
						echo "<script>alert('Part Number(产品料号)栏位中, 查询不到, 请重新建立...');history.go(-1);</script>";
						exit();
					}
					
					echo '<br>
					<table border="2" width="75%">
						<tr bgcolor="#70DB93">
							<th>No.</th>
							<th>工單</th>
							<th>Model Name</th>
							<th>Part Number</th>
							<th>WSID</th>
							<th>TPVER</th>
							<th>Create Date/Time</th>
							<th>Create By</th>
							<th>下載數</th>
							<th>近期下載</th>
						</tr>';
					
					while ( $getArray = mysqli_fetch_array($result,MYSQLI_ASSOC) ) {
						
						$put_pn          = $getArray['webdl_pn'];
						$put_wsid        = $getArray['webdl_wsid'];
						$put_tpver       = $getArray['webdl_tpver'];
						$put_work_order  = $getArray['webdl_work_order'];
						$put_line        = $getArray['webdl_line'];
						$put_panel       = $getArray['webdl_panel'];
						$put_create_date = $getArray['webdl_create_date'];
						$put_creator     = $getArray['webdl_creator'];
						$put_description = $getArray['webdl_description'];
						$put_ftpip       = $getArray['webdl_ftpip'];
						$put_count       = $getArray['webdl_count'];
						$put_date        = $getArray['webdl_download_date'];
						$standard_date 	 = strtotime(date($put_date));
					
															
					
						if ( $standard_date > $begin_date && $standard_date < $finish_date) {
							$c++;
							$show_num++;
							$param=array('INPUTSTRING'=>"<INPUTSTRING><rowset><DataType>A_NOTES_UPDATE_PRJECT_PE</DataType><KEY_PART_NO>$put_pn</KEY_PART_NO><Return_Formate>XML</Return_Formate></rowset></INPUTSTRING>");
							$res = $client->__Call("getSFData", array( $param ));
							if (is_soap_fault($res)) {
								trigger_error("SOAP Fault: (faultcode: {$res->faultcode}, faultstring: {$res->faultstring})", E_USER_ERROR);
							} else {
								$data = $res->getSFDataResult; //这里返回的是类，必须使用->得到元素的值
						
								
								if ( preg_match($regex, $data)){
									$model ="NOT Exists";
								} else {
									$start  = strpos($data,$starStr)+strlen($starStr);	//检索PROJECT PE : 在字符串中首次出现的位置。
									$end 	= strpos($data,$endStr);						//检索 N/A在字符串中末尾出现的位置。
									$model  = substr($data,$start,$end-$start);
								}																
							}
						
							echo "
								<tr>
									<th>$show_num</th>
									<th><font size='4' color='#0000FF'><b>$put_work_order</b></font></th>
									<th>$model</th>
									<th>$put_pn</th>
									<th>$put_wsid</th>
									<th>$put_tpver</th>
									<th>$put_create_date</th>
									<th>$put_creator</th>
									<th>$put_count</th>
									<th>$put_date</th>
								</tr>";
						} 
					}
					if ($c==0) {
						echo "<script>alert('该时间段无下载记录');history.go(-1);</script>";
						exit();
					} else {
						echo '</table><br>';
					}
					
					mysqli_free_result($result);			// 释放 MySQL $result
					mysqli_close($conn);					// 关闭资料库
					exit();
				} elseif ( strlen($begin1) > 0 && strlen($finish1) > 0 && strlen($partnum) > 0 ) {
					$c = 0;
					$conn = mysqli_connect(html::sql_login_host,html::sql_login_user,html::sql_login_pass,$db_select);
					if ( mysqli_connect_errno($conn) ) { 
						echo "<script>alert('MySql资料库连接失败,请联系开发人员,并查明原因...');history.go(-1);</script>";
						exit();
					}
					mysqli_set_charset($conn,'set names utf8');
					
			
					$sql_cmd = "SELECT * FROM `$db_table` WHERE `$table_name1`='$partnum'";					
					$result  = mysqli_query($conn,$sql_cmd);	// 透过 execute_query 对象实例完成查询
					if ( !$result ) { 
						mysqli_close($conn);				// 关闭资料库
						echo "<script>alert('MySql资料库搜寻失败,请跟开发人员查明原因...');history.go(-1);</script>";
						exit();
					}
					
					$rows = mysqli_num_rows($result);		// 返回结果集中栏位的数量。
					if ( $rows == 0 ) { 	
						echo "<script>alert('Part Number(产品料号)栏位中, 查询不到, 请重新建立...');history.go(-1);</script>";
						exit();
					}
					
					echo '<br>
					<table border="2" width="75%">
						<tr bgcolor="#70DB93">
							<th>No.</th>
							<th>工單</th>
							<th>Model Name</th>
							<th>Part Number</th>
							<th>WSID</th>
							<th>TPVER</th>
							<th>Create Date/Time</th>
							<th>Create By</th>
							<th>下載數</th>
							<th>近期下載</th>
						</tr>';
					
					while ( $getArray = mysqli_fetch_array($result,MYSQLI_ASSOC) ) {
						
						$put_pn          = $getArray['webdl_pn'];
						$put_wsid        = $getArray['webdl_wsid'];
						$put_tpver       = $getArray['webdl_tpver'];
						$put_work_order  = $getArray['webdl_work_order'];
						$put_line        = $getArray['webdl_line'];
						$put_panel       = $getArray['webdl_panel'];
						$put_create_date = $getArray['webdl_create_date'];
						$put_creator     = $getArray['webdl_creator'];
						$put_description = $getArray['webdl_description'];
						$put_ftpip       = $getArray['webdl_ftpip'];
						$put_count       = $getArray['webdl_count'];
						$put_date        = $getArray['webdl_download_date'];
						$standard_date 	 = strtotime(date($put_date));
																													
						if ( $standard_date > $begin_date && $standard_date < $finish_date ) {
							$c++;
							$show_num++;
							$param=array('INPUTSTRING'=>"<INPUTSTRING><rowset><DataType>A_NOTES_UPDATE_PRJECT_PE</DataType><KEY_PART_NO>$put_pn</KEY_PART_NO><Return_Formate>XML</Return_Formate></rowset></INPUTSTRING>");
							$res = $client->__Call("getSFData", array( $param ));
							if (is_soap_fault($res)) {
								trigger_error("SOAP Fault: (faultcode: {$res->faultcode}, faultstring: {$res->faultstring})", E_USER_ERROR);
							} else {
								$data = $res->getSFDataResult; //这里返回的是类，必须使用->得到元素的值
											
								if ( preg_match($regex, $data)){
									$model ="NOT Exists";
								} else {
									$start  = strpos($data,$starStr)+strlen($starStr);	//检索PROJECT PE : 在字符串中首次出现的位置。
									$end 	= strpos($data,$endStr);						//检索 N/A在字符串中末尾出现的位置。
									$model  = substr($data,$start,$end-$start);
								}
																		
							}
							
							echo "
								<tr>
									<th>$show_num</th>
									<th><font size='4' color='#0000FF'><b>$put_work_order</b></font></th>
									<th>$model</th>
									<th>$put_pn</th>
									<th>$put_wsid</th>
									<th>$put_tpver</th>
									<th>$put_create_date</th>
									<th>$put_creator</th>
									<th>$put_count</th>
									<th>$put_date</th>
								</tr>";
						} 											
					}
					if ($c==0) {
						echo "<script>alert('该时间段无下载记录');history.go(-1);</script>";
						exit();
					} else {
						echo '</table><br>';
					}
					mysqli_free_result($result);			// 释放 MySQL $result
					mysqli_close($conn);					// 关闭资料库
					exit();
				} elseif ( strlen($begin1) == 0 && strlen($finish1) == 0 && strlen($partnum) > 0 ) {		
					$conn = mysqli_connect(html::sql_login_host,html::sql_login_user,html::sql_login_pass,$db_select);
					if ( mysqli_connect_errno($conn) ) { 
						echo "<script>alert('MySql资料库连接失败,请联系开发人员,并查明原因...');history.go(-1);</script>";
						exit();
					}
					mysqli_set_charset($conn,'set names utf8');
									
					$sql_cmd = "SELECT * FROM `$db_table` WHERE `$table_name1`='$partnum'";
					
					$result = mysqli_query($conn,$sql_cmd);	// 透过 execute_query 对象实例完成查询
					if ( !$result ) { 
						mysqli_close($conn);				// 关闭资料库
						echo "<script>alert('MySql资料库搜寻失败,请跟开发人员查明原因...');history.go(-1);</script>";
						exit();
					}
					
					$rows = mysqli_num_rows($result);		// 返回结果集中栏位的数量。
					if ( $rows == 0 ) { 	
						echo "<script>alert('Part Number(产品料号)栏位中, 查询不到, 请重新建立...');history.go(-1);</script>";
						exit();
					}
					
					echo '<br>
					<table border="2" width="75%">
						<tr bgcolor="#70DB93">
							<th>No.</th>
							<th>工單</th>
							<th>Model Name</th>
							<th>Part Number</th>
							<th>WSID</th>
							<th>TPVER</th>
							<th>Create Date/Time</th>
							<th>Create By</th>
							<th>下載數</th>
							<th>近期下載</th>
						</tr>';
					
					while ( $getArray = mysqli_fetch_array($result,MYSQLI_ASSOC) ) {
						$show_num++;
						$put_pn          = $getArray['webdl_pn'];
						$put_wsid        = $getArray['webdl_wsid'];
						$put_tpver       = $getArray['webdl_tpver'];
						$put_work_order  = $getArray['webdl_work_order'];
						$put_line        = $getArray['webdl_line'];
						$put_panel       = $getArray['webdl_panel'];
						$put_create_date = $getArray['webdl_create_date'];
						$put_creator     = $getArray['webdl_creator'];
						$put_description = $getArray['webdl_description'];
						$put_ftpip       = $getArray['webdl_ftpip'];
						$put_count       = $getArray['webdl_count'];
						$put_date        = $getArray['webdl_download_date'];
						$standard_date 	 = strtotime(date($put_date));																								
						$param=array('INPUTSTRING'=>"<INPUTSTRING><rowset><DataType>A_NOTES_UPDATE_PRJECT_PE</DataType><KEY_PART_NO>$put_pn</KEY_PART_NO><Return_Formate>XML</Return_Formate></rowset></INPUTSTRING>");
						$res = $client->__Call("getSFData", array( $param ));
						if (is_soap_fault($res)) {
							trigger_error("SOAP Fault: (faultcode: {$res->faultcode}, faultstring: {$res->faultstring})", E_USER_ERROR);
						} else {
							$data = $res->getSFDataResult; //这里返回的是类，必须使用->得到元素的值
					
							
							if ( preg_match($regex, $data)){
								$model ="NOT Exists";
							} else {
								$start  = strpos($data,$starStr)+strlen($starStr);	//检索PROJECT PE : 在字符串中首次出现的位置。
								$end 	= strpos($data,$endStr);						//检索 N/A在字符串中末尾出现的位置。
								$model  = substr($data,$start,$end-$start);
							}															
						}
						
						echo "
							<tr>
								<th>$show_num</th>
								<th><font size='4' color='#0000FF'><b>$put_work_order</b></font></th>
								<th>$model</th>
								<th>$put_pn</th>
								<th>$put_wsid</th>
								<th>$put_tpver</th>
								<th>$put_create_date</th>
								<th>$put_creator</th>
								<th>$put_count</th>
								<th>$put_date</th>
							</tr>";
					}
					echo '</table><br>';
					mysqli_free_result($result);			// 释放 MySQL $result
					mysqli_close($conn);					// 关闭资料库
					exit();
				} else {
					echo "<script>alert('请输入對應所需查詢信息');history.go(-1);</script>";
					exit();
				}
			?>
		</center>
	</body>
</html>

